﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Script.Serialization;
using System.Data;
using FlexiGridHelper;

namespace Golf.WebUI.HttpHandler.Comment
{
    /// <summary>
    /// CommentList 的摘要说明
    /// </summary>
    public class CommentList : IHttpHandler
    {
        Golf.BLL.Golf_Comment cont = new BLL.Golf_Comment();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Golf.Model.Golf_Comment> list = new List<Golf.Model.Golf_Comment>();
           // comment=cont.GetAllList();
            PageView pageView = new PageView(context);
            //获取数据集 分页数据集
           // List<Golf_Comment> pagerList = comment.Skip((pageview.PageIndex - 1) * pageview.PageSize).Take(pageview.PageSize).ToList();
            DataSet ds = cont.GetList(pageView.PageSize, pageView.PageIndex, "0=0");
            //构建表格
            DataTable dt = new DataTable();
            //构建列
            DataColumn dc0 = new DataColumn("Id", typeof(string));
            DataColumn dc1 = new DataColumn("OrderNumber", typeof(string));
            DataColumn dc2 = new DataColumn("UserId", typeof(string));
            DataColumn dc3 = new DataColumn("FristName", typeof(string));
            DataColumn dc4 = new DataColumn("LastName", typeof(string));
            DataColumn dc5 = new DataColumn("ProductId", typeof(string));
            DataColumn dc6 = new DataColumn("CommentTitle", typeof(string));
            DataColumn dc7 = new DataColumn("CommentContent", typeof(string));
            DataColumn dc8 = new DataColumn("CommentTime", typeof(string));
            DataColumn dc9 = new DataColumn("CommentIp", typeof(string));
            DataColumn dc10 = new DataColumn("CommentScore", typeof(string));
            DataColumn dc11 = new DataColumn("CommentNum", typeof(string));
            DataColumn dc12 = new DataColumn("IsShow", typeof(string));
            //添加到 构建的数据表中
            dt.Columns.AddRange(new DataColumn[] { dc0, dc1, dc2, dc3, dc4, dc5, dc6, dc7, dc8, dc9, dc10, dc11,dc12 });
            list = cont.DataTableToList(ds.Tables[0]);
         //填充数据
            foreach (var item in list)
            {
                //兴建行
                DataRow dr = dt.NewRow();
                dr["Id"] = item.Id;
                dr["OrderNumber"] = item.OrderNumber;
                dr["UserId"] = item.UserId;
                dr["FristName"] = item.FristName;
                dr["LastName"] = item.LastName;
                dr["ProductId"] = item.ProductId;
                dr["CommentTitle"] = item.CommentTitle;
                dr["CommentContent"] = item.CommentContent;
                dr["CommentTime"] = item.CommentTime;
                dr["CommentIp"] = item.CommentIp;
                dr["CommentScore"] = item.CommentScore;
                dr["CommentNum"] = item.CommentNum;
                dr["IsShow"] = item.IsShow;
                dt.Rows.Add(dr);
            }
            //调用转
            context.Response.Write(js.Serialize(new GetDataHelper().GetFlexiGridData(pageView, dt, list.Count)));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}